package com.zijie.hosptal.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zijie.hosptal.pojo.po.Reserve;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface ReserveMapper extends BaseMapper<Reserve> {
    Page<Reserve> findList(Page<Reserve> reservePage, Reserve reserve);


    boolean rateReserve(Reserve reserve);

    boolean saveOrUpdateBatch(List<Reserve> list);

    @Select("select count(1) from reserve")
    Integer getReserveTotal();

   

    //日历中当天的预约人数
    @Select("select count(1) from reserve where schedule_id=#{id} and status!='0'")
    Integer selectByDSId(Integer id);


    @Select("select * from reserve where date(reserve_time)=date(#{reserveTime}) and patient_id=#{patientId} and status!='0' limit  1")
    Reserve selectByReserveTime(LocalDateTime reserveTime, Integer patientId);

    @Update("update reserve set status=#{status} where id=#{id}")
    boolean removeReserve(Reserve reserve);

    Integer getByReserveId(Integer scheduleId, String status);

    Page<Reserve> listReserves(Page<Reserve> reservePage, Reserve reserve);

    @Select("select id,patient_id,score,time,status,schedule_id from reserve where schedule_id=#{id}")
    Reserve selectByDSIdToReserve(Integer id);

    @Select("select id from reserve where patient_id= #{patientId} and schedule_id= #{scheduleId} and status!='0' limit 1")
    Integer selectByPatientId(Integer patientId, Integer scheduleId);

    @Select("select schedule_id from reserve where  status='1' and patient_id=#{patientId}")
    List<Integer> selectToDay(LocalDateTime startTime, Integer patientId);
}
